package com.kevin.enterprise.dao;

import com.kevin.enterprise.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class LoginServletDao {
    Connection conn=null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String sql = null;

    public boolean selectByID(String userName, String password) {
        try {
            //int userName1 = Integer.parseInt(userName);
            //sql = "select * from student where id=? and name=?";
            sql = "select sno,password from student where sno=? and password=?";
            conn = JdbcUtils.getConnection();
            pstmt = conn.prepareStatement(sql);
            //pstmt.setInt(1, userName1);
            pstmt.setString(1, userName);
            pstmt.setString(2, password);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                System.out.println("登录成功");
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.getClose(conn,pstmt,rs);
        }
        return false;
    }
}
